package com.parking.mgr.common.config;

import cn.hutool.core.io.resource.ResourceUtil;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @ClassName I18NJsonFileConfig
 * @Description TODO
 * @author: zhijianpu
 * @Date: 2023/7/29
 */
@Component
public class I18NJsonFileConfig implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public String loadJson(String lang) {
        return ResourceUtil.readUtf8Str("i18n/" + lang + ".json");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        I18NJsonFileConfig.applicationContext = applicationContext;
    }

    public static <T> T getBean(Class<T> clazz) {
        return applicationContext != null?applicationContext.getBean(clazz):null;
    }
}
